<?php


namespace app\business\model;


use think\Model;

class CommodityAppraises extends Model
{
    /**
     * @evaluation  商家评价管理-其他
     * @param $businessId
     * @param $evaluationStatus
     * @return CommodityAppraises[]
     */
    public function evaluation(int $businessId,string $evaluationStatus){
        return $this->table('commodityAppraises')
            ->field('id,businessId,orderId,commodityId,commodityScore,serviceScore,timeScore,content,evaluationStatus,businessReply')
            ->where([
                'businessId'        =>  $businessId,
                'evaluationStatus'  =>  $evaluationStatus
            ])
            ->select();
    }

    /**
     * @param int $businessId
     * @return CommodityAppraises[]
     */
    public function evaluationAll(int $businessId){
        return $this->table('commodityAppraises')
            ->field('id,businessId,orderId,commodityId,commodityScore,serviceScore,timeScore,content,evaluationStatus,businessReply')
            ->where('businessId',$businessId)
            ->select();
    }

    /**
     * @reply   商家回复评论
     * @param $reply
     * @param $commodityAppraisesId
     * @return CommodityAppraises
     */
    public function reply(string $reply,int $orderId){
        return $this->table('commodityAppraises')
            ->where('orderId',$orderId)
            ->update([
                'businessReply'     =>  $reply,
                'evaluationStatus'  =>  0,
                'replyTime'         =>  time(),
                'updateTime'        =>  time()
            ]);
    }
}